import React from 'react'
import Config from '../../Config'

class TextArea extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      scrollHeight:this.props.height?this.props.height:20
  }}
  onChange=(e)=>{
    let a = {}
    for(let i in e.target){
      a[i] = e.target[i]
    }
    this.setState({
      scrollHeight:e.target.scrollHeight
    })
    this.props.onChange(e.target.value)
  }
  render() {
    const { placeholder, style } = this.props
    return (
      <textarea
        style={{ ...inputStyle, ...style ,height:this.state.scrollHeight+'px'}}
        onChange={
          e=>this.onChange(e)
        }
        onBlur={
          e=>this.onChange(e)
        }
        placeholder={placeholder}
      />
    )
  }
}

const inputStyle = {
  border: 'none',
  outline: 'none',
  width: '100%',
  height: '20px',
  lineHeight: '20px',
  fontSize: '14px',
  color: Config.fontColor1,
}
export default TextArea